import request from '@/utils/request'
import Cookies from 'js-cookie'

// 获取我的信息
export function getLoginInfo() {
    if (Cookies.get('Authorization')) {
        return request({
            url: '/user/me',
            method: 'get'
        })
    }
    return Promise.reject('未登录')
}

// 修改头像
export function changeAvatar(data: FormData) {
    return request({
        url: '/user/me/avatar',
        method: 'patch',
        headers: {
            'Content-Type': 'multipart/form-data'
        },
        data
    })
}

// 修改邮箱
export function changeEmail(email: string) {
    return request({
        url: '/user/me/email',
        method: 'patch',
        data: {
            email
        }
    })
}

// 修改密码
export function changePassword(oldPassword: string, newPassword: string) {
    return request({
        url: '/user/me/password',
        method: 'patch',
        data: {
            oldPassword,
            newPassword
        }
    })
}

// 获取用户信息
export function getUserInfo(id: number | string) {
    return request({
        url: `/user/uid/${id}`,
        method: 'get'
    })
}